package cn.akwangl.spring.ioc.container;

import cn.akwangl.spring.ioc.model.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * {@link ApplicationContext} IOC容器
 *
 * @author youyongkun
 * @date 2021/6/29 9:15
 */
public class ApplicationContextAsIocContainerDemo {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(ApplicationContextAsIocContainerDemo.class);
        applicationContext.refresh();


        User user = applicationContext.getBean("user", User.class);
        System.out.println(user);
    }

    @Bean
    public User user(){
        User user = new User();
        user.setId("1");
        user.setName("akwangl");
        return user;
    }

}
